home *** CD-ROM | disk | FTP | other *** search
- /*
- This macro shows how to write a very simple tcp service
- to be called by inetd.
- To use this service, you must:
- - be sure you copied "rxs" from rxsocket.lha to C:
- - copy pserv.rexx TO ram:
- - add to the services database:
- ARexxRevServ 4000/tcp
- - add to the inedt database:
- ARexxRevServ stream tcp nowait root c:rxs rxs ram:pserv.rexx
- (port number 4000 can be changed to any free tcp port).
- To test the service just use revclient.
- if the env var "PSERV_LOG" is set to 1, it logs the connection.
- */
-
- if ~show("L","rexxsupport.library") then
- if ~addlib("rexxsupport.library",0,-30) then do
- say "no rexxsupport.library"
- exit
- end
- if ~show("L","rxsocket.library") then
- if ~addlib("rxsocket.library",0,-30) then do
- say "no rxsocket.library"
- exit
- end
- if ~show("L","rmh.library") then
- if ~addlib("rmh.library",0,-30) then do
- say "no rmh.library"
- exit
- end
-
- prg = ProgramName("NOEXT")
-
- /* Here we test if socket number 0 exists.
- If it does we were called from inetd.
- If it doesn't, we weren't called from inetd and we exit. */
- if ~IsSocket(0) then do
- say prg": this service must be run from rxs in inedt"
- exit
- end
-
- /* who connected us? Let's try to get info, if error log that */
- if ~GetSockName(0,"NAME")<0 then do
- call SysLog(prg "Can't get peer info ("errno()")")
- exit
- end
-
- if getclip("PSERV_LOG")==1 then do
- /* log the connection */
- msg = "pserv Connection from" name.addrAddr
- if GetHostByAddr("HOST",name.addrAddr) then msg = msg "("host.hostName")"
- call SysLog(msg)
- end
-
- /* the service itself */
- len = recv(0,"BUF",256)
- if len<0 then do
- call SysLog("pserv Error reading ("errno()")")
- exit
- end
-
- buf = reverse(buf)
- if send(0,BUF)~=length(buf) then do
- call SysLog("pserv Error sending ("errno()")")
- exit
- end
-